package com.cloud.code.算法.leetCode;

import java.util.HashMap;
import java.util.Map;

public class LeetCode3 {


    public static int lengthOfLongestSubstring(String s) {

        int max = 0;
        char[] chars = s.toCharArray();
        int left = 0;
        int right = 0;
        Map<Character, Integer> map = new HashMap<>();
        while (right < chars.length) {

            char aChar = chars[right++];
            map.put(aChar, map.getOrDefault(aChar, 0) + 1);

            while (map.get(aChar) > 1) {
                char aChar1 = chars[left++];
                map.put(aChar1, map.getOrDefault(aChar1, 0) - 1);
            }

            max = Math.max(max, right - left);


        }

        return max;

    }
}
